<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /**
     * promise.finally(() => {    默认是上一次回调（不论成功或失败）的结果
     *   // do something          一般是不需要加参数的
     * });
     *
     * // 等同于
     * promise.then(
     *   result => {
     *     // do something
     *     return result;
     *   },
     *   error => {
     *     // do something
     *     throw error;
     *   }
     * );
     * @type {Promise<unknown>}
     */

    const p1 = new Promise((resolve) => {
        setTimeout(() => {
            resolve("resolve3")
            console.log("timer1")
        }, 0)
        resolve("resolve1")
        resolve("resolve2") // 无效
    }).then(res => {
        console.log(res)
        setTimeout(() => {
            console.log(p1)
        }, 1000)
    }).finally(res => {
        console.log("finally", res)
    })

</script>
</body>
</html>